# # 统计人数
#
#
# import csv
#
# with open('titanic.csv', 'r') as file:
#     reader = csv.reader(file)
#     next(reader)  # 跳过标题行
#     passenger_count = sum(1 for row in reader)
#
# print(f"乘客人数: {passenger_count}")
#
#
# # 统计男女比例
#
#
# import csv
#
# male_count = 0
# female_count = 0
#
# with open('titanic.csv', 'r') as file:
#     reader = csv.DictReader(file)
#     for row in reader:
#         if row['Sex'] == 'male':
#             male_count += 1
#         elif row['Sex'] == 'female':
#             female_count += 1
#
# total_passengers = male_count + female_count
# male_ratio = male_count / total_passengers
# female_ratio = female_count / total_passengers
#
# print(f"男性乘客人数: {male_count}")
# print(f"女性乘客人数: {female_count}")
# print(f"男女比例: 男性 {male_ratio:.2%}, 女性 {female_ratio:.2%}")
#
#
# # 计算大于35岁人员姓名
#
# import csv
#
# names_above_35 = []
#
# with open('titanic.csv', 'r') as file:
#     reader = csv.DictReader(file)
#     for row in reader:
#         if row['Age'] and float(row['Age']) > 35:
#             names_above_35.append(row['Name'])
#
# print("大于35岁的人员姓名:")
# for name in names_above_35:
#     print(name)
#
#
# # 计算平均票价
#
#
import csv

total_fare = 0
passenger_count = 0

with open('titanic.csv', 'r') as file:
    reader = csv.DictReader(file)
    for row in reader:
        if row['Fare']:
            total_fare += float(row['Fare'])
            passenger_count += 1

average_fare = total_fare / passenger_count
print(f"平均票价: {average_fare:.2f}")
